#pragma once
#include "stdafx.h"

template <class T> class My_vector1 :/*protected*/private vector<T>
{
	T begin_val{};
	T end_val{};

public:
	My_vector1() = default;
	My_vector1(const T& begin, const T& end) :begin_val{ begin }, end_val{ end }, vector<T>() {}
	My_vector1(const T&, const T&, initializer_list<T>);

	using vector<T>::pop_back;
	//using vector<T>::size;
	int Size() { return this->size(); }

	void back_insert(initializer_list<T>);
	void erase_if(initializer_list<T>);

	
	void Sort(char x = '<');
	void print_container();
	~My_vector1() = default;

};

template<class T>
inline My_vector1<T>::My_vector1(const T& begin, const T& end, initializer_list<T> l)
	:begin_val{ begin }, end_val{ end }
{
	for (auto &val : l)
	{
		if (val >= begin_val && val <= end_val)
		{
			if (std::find(this->begin(), this->end(), val) == this->end())
			{
				this->push_back(val);//����������� ��� �������� �� �����
			}
		}
	}
}

template<class T>
inline void My_vector1<T>::back_insert(initializer_list<T> l)
{
	for (auto& val : l)
	{
		if (val >= begin_val && val <= end_val)
		{
			if (std::find(this->begin(), this->end(), val) == this->end())
			{
				this->push_back(val);//����������� ��� �������� �� �����
			}
		}
	}
	/*return *this;*/
}

template<class T>
inline void My_vector1<T>::erase_if(initializer_list<T> l)
{
	auto l1 = [&](const auto& val)
	{ bool fl = false;
		for (auto& x : l)
		{
			if (x == val) { fl = true; break; }
		}
	  return fl; 
	};

	auto it = remove_if(this->begin(), this->end(), l1);
	this->erase(it, this->end());
	/*return *this;*/
}

template<class T>
inline void My_vector1<T>::Sort(char x)
{
	std::sort(this->begin(), this->end(), [&](const auto& a, const auto& b) {return x == '>' ? a > b:a < b; });
}

template<class T>
inline void My_vector1<T>::print_container()
{
	for (size_t i = 0; i < this->size(); i++)
	{
		std::cout << this->operator[](i) << " ";
	}
	std::cout << std::endl;
}